package com.restclient.test.restclient;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.WebResource.Builder;
import com.sun.jersey.core.util.Base64;
import com.sun.jersey.core.util.MultivaluedMapImpl;

public class JerseyRestClient {
	public static void main(String[] args) {
		Client client = Client.create();
		WebResource webresource = client
				.resource("http://172.23.233.95/app/api/rest");
		String value = "B5840C393C6743FA91AD377681465E68";
		String headerkey = "X-Cloupia-Request-Key";

		MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
		queryParams.add("formatType", "json");
		queryParams.add("opName", "vacs:userAPIGetStaticNAT");
		queryParams.add("opData", "{param0:57}");

		WebResource newre = webresource.queryParams(queryParams);
		Builder pr = newre.accept(MediaType.APPLICATION_JSON_TYPE,
				MediaType.APPLICATION_XML_TYPE).header(headerkey, value);
		String b = pr.get(String.class);

		webresource.queryParams(queryParams);

		System.out.println("output: " + b);
		byte[] encoded = Base64.encode("adminadmin");
		System.out.println("encoded pattern:" + encoded.toString());
	}
}
